From 0b053096f2e142e7ef7862cf44091f083f681d8e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 3 Sep 2017 15:06:37 +0200 Subject: [PATCH] babl: make error argument of babl_space_from_icc optional --- babl/babl-icc.c | 26 +++++++++----------------- babl/babl-internal.h | 3 --- babl/babl.h | 20 ++++++++++++-------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/babl/babl-icc.c b/babl/babl-icc.c index a79f21b..3fa24e9 100644 --- a/babl/babl-icc.c +++ b/babl/babl-icc.c @@ -300,7 +300,7 @@ static int icc_tag (ICC *state, } static const Babl *babl_trc_from_icc (ICC *state, int offset, - char **error) + const char **error) { { int count = icc_read (u32, offset + 8); @@ -417,25 +417,13 @@ switch (trc->type) icc_write (u32, state->o + 8, 0); break; case BABL_TRC_FORMULA_GAMMA: - icc_allocate_tag (state, name, 14); - icc_write (sign, state->o, "curv"); - icc_write (u32, state->o + 4, 0); - icc_write (u32, state->o + 8, 1); - icc_write (u8f8, state->o + 12, trc->gamma); - break; case BABL_TRC_GAMMA_1_8: - icc_allocate_tag (state, name, 14); - icc_write (sign, state->o, "curv"); - icc_write (u32, state->o + 4, 0); - icc_write (u32, state->o + 8, 1); - icc_write (u8f8, state->o + 12, 1.8); - break; case BABL_TRC_GAMMA_2_2: icc_allocate_tag (state, name, 14); icc_write (sign, state->o, "curv"); icc_write (u32, state->o + 4, 0); icc_write (u32, state->o + 8, 1); - icc_write (u8f8, state->o + 12, 2.2); + icc_write (u8f8, state->o + 12, trc->gamma); break; case BABL_TRC_LUT: icc_allocate_tag (state, name, 13 + trc->lut_size * 2); @@ -634,9 +622,9 @@ static char *icc_decode_mluc (ICC *state, int offset, int element_length, char * } const Babl * -babl_space_from_icc (const char *icc_data, - int icc_length, - char **error) +babl_space_from_icc (const char *icc_data, + int icc_length, + const char **error) { ICC *state = icc_state_new ((char*)icc_data, icc_length, 0); int profile_size = icc_read (u32, 0); @@ -644,11 +632,15 @@ babl_space_from_icc (const char *icc_data, const Babl *trc_red = NULL; const Babl *trc_green = NULL; const Babl *trc_blue = NULL; + const char *int_err; char *descr = NULL; char *copyright = NULL; sign_t profile_class, color_space; + if (!error) error = &int_err; + *error = NULL; + if (profile_size != icc_length) { *error = "icc profile length inconsistency"; diff --git a/babl/babl-internal.h b/babl/babl-internal.h index c7c87cf..6593862 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -349,9 +349,6 @@ babl_trc_new (const char *name, void babl_space_to_xyz (const Babl *space, const double *rgb, double *xyz); void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb); -const Babl *babl_space_from_icc (const char *icc, - int length, - char **error); const Babl *babl_trc_lut_find (float *lut, int lut_size); const Babl *babl_trc_lut (const char *name, int n, float *entries); diff --git a/babl/babl.h b/babl/babl.h index a992dad..3527a60 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -146,28 +146,32 @@ babl_space_from_rgbxyz_matrix (const char *name, /** * babl_space_from_icc: * + * @icc_data: pointer to icc profile in memory + * @icc_length: length of icc profile in bytes + " @error: pointer to a string where decoding errors can be stored, + * if an error occurs, NULL is returned and an error message + * is provided in error. + * * Create a babl space from an in memory ICC profile, the * profile does no longer need to be loaded for the space to work, * multiple calls with the same icc profile will result in the * same space. * - * For now, limited to v2 ICC profiles, support for v4 profiles will be added. - * - * babl uses internal parametric TRCs when the provided LUTs are sufficiently - * similar. - * * If a BablSpace cannot be created from the profile NULL is returned and * a static string is set on the provided error location. */ -const Babl *babl_space_from_icc (const char *icc_data, - int icc_length, - char **error); +const Babl *babl_space_from_icc (const char *icc_data, + int icc_length, + const char **error); /* babl_space_to_icc: * * Creates an ICCv2 RGB matrix profile for a babl space. The profiles strive to * be as small and compact as possible, TRCs are stored as 1024 entry LUT(s). + * + * you should make a copy of the profile before making another call to this + * function. */ const char *babl_space_to_icc (const Babl *space, int *icc_length); -- 2.30.2